package net.lesscoding.shop.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author eleven
 * @date 2024/6/7 16:05
 * @apiNote
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    private Integer code;

    private String message;

    private T data;


    public static <T> Result<T> success(T data) {
        return success( "success", data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<T>(200, message, data);
    }

    public static <T> Result<T> success(String message) {
        return success(message, null);
    }

    public static Result<Boolean> failed(String message) {
        return new Result<>(400, message, false);
    }

    public static Result<Boolean> error(Throwable t) {
        return new Result<>(500, t.getMessage(), false);
    }
}
